home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / jcool01.zip / EX9_11.C < prev    next >
C/C++ Source or Header  |  1992-10-05  |  3KB  |  53 lines

  1. //
  2. // Copyright (C) 1991 Texas Instruments Incorporated.
  3. //
  4. // Permission is granted to any individual or institution to use, copy, modify,
  5. // and distribute this software, provided that this complete copyright and
  6. // permission notice is maintained, intact, in all copies and supporting
  7. // documentation.
  8. //
  9. // Texas Instruments Incorporated provides this software "as is" without
  10. // express or implied warranty.
  11. //
  12. // Updated: JAM 10/05/92 -- modernized template syntax
  13. // Updated: JAM 10/05/92 -- fixed bug where nodes dtors called multiple times
  14. //                          by making auto Nodes pointers and letting the
  15. //                          Tree dtor delete them recursively
  16.  
  17. #include <cool/D_Node.h>            // Include node class
  18. #include <cool/N_Tree.h>            // Include n-ary tree class
  19. #include <cool/String.h>            // Include COOL String class
  20.  
  21. #include <cool/Vector.C>
  22. #include <cool/D_Node.C>
  23. #include <cool/N_Tree.C>
  24.  
  25. int main (void) {
  26.   CoolD_Node<CoolString,3>* president = new CoolD_Node<CoolString,3>(CoolString("President")); // Create president
  27.   CoolN_Tree<CoolD_Node<CoolString,3> > org_chart (president);    // Setup top of tree
  28.   CoolD_Node<CoolString,3>* sales = new CoolD_Node<CoolString,3>(CoolString("Sales"));        // Create sales
  29.   CoolD_Node<CoolString,3>* service = new CoolD_Node<CoolString,3>(CoolString("Service"));    // Create service
  30.   CoolD_Node<CoolString,3>* finance = new CoolD_Node<CoolString,3>(CoolString("Finance"));    // Create finance
  31.   CoolD_Node<CoolString,3>* legal = new CoolD_Node<CoolString,3>(CoolString("Legal"));        // Create legal
  32.   (*president)[0] = sales;                    // Add sales to chart
  33.   president->insert_after(*service, 0);                // Add service to chart
  34.   president->insert_after(*finance, 1);                // Add finance to chart
  35.   president->insert_after(*legal, 2);                // Add legal to chart
  36.   (*sales)[0] = new CoolD_Node<CoolString,3> (CoolString("Domestic")); // Domestic sales
  37.   CoolD_Node<CoolString,3>* international = new CoolD_Node<CoolString,3>(CoolString("International")); // International
  38.   sales->insert_after(*international, 0);
  39.   (*international)[0] = new CoolD_Node<CoolString,3> (CoolString("Asia"));
  40.   international->insert_after(*(new CoolD_Node<CoolString,3> (CoolString("Europe"))), 0);
  41.   international->insert_after(*(new CoolD_Node<CoolString,3> (CoolString("Africa"))), 1);
  42.   (*finance)[0] = new CoolD_Node<CoolString,3> (CoolString("Short Term"));
  43.   finance->insert_after(*(new CoolD_Node<CoolString,3> (CoolString("Long Term"))), 0);
  44.   finance->insert_after(*(new CoolD_Node<CoolString,3> (CoolString("Collections"))), 1);
  45.   org_chart.traversal() = PREORDER;        // Set traversal mode
  46.   for (org_chart.reset (); org_chart.next (); ) { // For each node in tree
  47.     for (int i = 0; i < org_chart.current_depth (); i++) // Indent level
  48.       cout << "   ";
  49.     cout << org_chart.value () << "\n";
  50.   }
  51.   return (0);                    // Return success
  52. }
  53.